//
//  FQDSearchBarButton.m
//  FakeQDaily
//
//  Created by mewxiv on 8/28/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDSearchBarButton.h"

#import "Masonry.h"

@interface FQDSearchBarButton ()

// 搜索图标icon
@property (nonatomic, strong) UIImageView *searchIcon;
// “搜索”文本
@property (nonatomic, strong) UILabel *searchLabel;

@end

@implementation FQDSearchBarButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareUI];
        [self prepareConstraints];
    }
    return self;
}

- (void)prepareUI
{
    self.layer.backgroundColor = RGBA(178.0f, 178.0f, 178.0f, 77.0f).CGColor;
    self.layer.cornerRadius = 18.0f;
    
    UIImage *searchIconImage = [UIImage imageNamed:@"a_search icon"];
    _searchIcon = [[UIImageView alloc] initWithImage:searchIconImage];
    [self addSubview:_searchIcon];
    
    _searchLabel = [[UILabel alloc] init];
    _searchLabel.font = FQDRegularFontWithSize(14.0f);
    _searchLabel.textColor = RGB(170, 170, 170);
    _searchLabel.text = @"搜索";
    [_searchLabel sizeToFit];
    [self addSubview:_searchLabel];
}

- (void)prepareConstraints
{
    WeakSelf;
    
    [_searchIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).offset(18);
        make.centerY.equalTo(weakSelf);
        make.size.equalTo(@(17));
    }];
    
    [_searchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.searchIcon.mas_right).offset(5);
        make.centerY.equalTo(weakSelf);
    }];
}

@end